package com.project.oauth2Server.common.redis;

import com.project.thisDatabase.redis.RedisConnectionConfig;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Configuration
@Component
public class RedisAuthConfig {
    @Value(value = "${spring.data.redis.database:}")
    private String dbIndex;

    @Value(value = "${spring.data.redis.host:}")
    private String hostName;

    @Value(value = "${spring.data.redis.port:}")
    private String port;

    @Value(value = "${spring.data.redis.password:}")
    private String password;

    @Value(value = "${spring.data.redis.lettuce.pool.max-idle:}")
    private String maxIdle;

    @Value(value = "${spring.data.redis.lettuce.pool.min-idle:}")
    private String minIdle;

    @Value(value = "${spring.data.redis.lettuce.pool.max-active:}")
    private String maxActive;

    @Value(value = "${spring.data.redis.lettuce.pool.max-wait:}")
    private String maxWait;

    @Value(value = "${spring.data.redis.timeout:}")
    private String timeOut;

    @Value(value = "${spring.data.redis.timeout:}")
    private String shutdownTimeOut;

    @Bean(name = "redis_template_auth")
    public RedisTemplate<Object, Object> redisTemplateAuth() {
        System.out.println("redis link to " + hostName);
        return RedisConnectionConfig.createRedisTemplate(
                Integer.parseInt(dbIndex),
                hostName,
                Integer.parseInt(port),
                password,
                Integer.parseInt(maxIdle),
                Integer.parseInt(minIdle),
                Integer.parseInt(maxActive),
                Long.parseLong(maxWait),
                Long.parseLong(timeOut),
                Long.parseLong(shutdownTimeOut)
        );
    }
}
